package com.ken.elmboot.config;

import com.ken.elmboot.interceptor.LoginInsterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ken
 */
@Configuration
public class MvcConfig {
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/upload/**").addResourceLocations("file:D:/Download/upload/");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                InterceptorRegistration registration = registry.addInterceptor(new LoginInsterceptor());
                //所有路径都被拦截
                registration.addPathPatterns("/**");
                //添加不拦截的路径
                registration.excludePathPatterns(
                        "/sys/admin/login", // 登录不能被拦截
                        "/validatecode", //验证码不能被拦截
                        "/login.html", //登录页面不能被拦截
                        "/css/**", // css静态资源不能被拦截
                        "/js/**", // js静态资源不能被拦截
                        "/images/**", // image静态资源不能被拦截
                        "/upload/**" // 上传页面不能被拦截
                );
            }
        };
    }
}
